import java.text.Format;

public class Rational {
	public float numberator;
	public float denominator;
	public Rational(){
		numberator = 0 ;
		denominator = 1 ;
	}
	public Rational(float numberator, float denominator)
	{
		this.numberator = numberator;
		this.denominator = denominator;
	}
	public Boolean KT(float numberator, float ms){
		return ms == 1;
	}
    public static Rational Rational(int SN) 
    {
        return  new Rational(SN, 1);
    }
	  public static int UCLN(float a, float b)
      {
          if(b==0)
              return (int)a;
          else
              return UCLN(b, a%b);
      }
	  public void Reduce(Rational p){
		  int uoc =  UCLN(Math.abs(p.numberator),Math.abs(p.denominator));
		  float ts1 = p.numberator/uoc;
		  float ms1 = p.denominator/uoc;
		  System.out.print("\n"+ts1 + "/"+ ms1);
		  
	  }
	  public void Reciprocal(Rational a){
		 // a.ToString();
		   Rational p = new Rational();
		if(a.numberator!= 0)
			    p = new Rational(a.denominator,a.numberator);
		  Reduce(p);
	  }
	  public void Add(Rational p1, Rational p2){
		  Rational kq;
          if (p1.denominator != p2.denominator)
          {
              kq = new Rational(p1.numberator * p2.denominator + p2.numberator * p1.denominator, p1.denominator * p2.denominator);
          }
          else
              kq = new Rational(p1.numberator + p2.numberator, p1.denominator);
         Reduce(kq);
          
      }
	  public void Subtract(Rational p1, Rational p2){
		  Rational kq;
          if (p1.denominator != p2.denominator)
          {
              kq = new Rational(p1.numberator * p2.denominator - p2.numberator * p1.denominator, p1.denominator * p2.denominator);
          }
          else
              kq = new Rational(p1.numberator - p2.numberator, p1.denominator);
         Reduce(kq);
          
      }
	  public void Multiply(Rational p1, Rational p2){
		  Rational kq = new Rational(p1.numberator * p2.numberator, p1.denominator*p2.denominator);
		  Reduce(kq);
	  }
	  public void Divide(Rational p1, Rational p2){
		  Rational kq;
		  if(p2.numberator == 0)  
			  {
			  System.out.print("khong the chia cho khong");
			  kq = null;
			  }
		  else 
			  kq = new Rational(p1.numberator * p2.denominator,p2.numberator*p1.denominator);
		  Reduce(kq);
	  }
	  
	  public static void main(String[] args)
	  {
		  Rational a = new Rational(4,6);
		  a.Reduce(a);
		  Rational kq = new Rational();
		  Rational b = new Rational(3,4);
		  kq.Add(a,b);
		  kq.Reciprocal(a);
		  kq.Subtract(a, b);
		  kq.Multiply(a, b);
		  kq.Divide(a, b);
	  }
}
interface Comparable{
	void lonhon();
	void bang();
	void nhohon();
}
